<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>findLastKey</title>
</head>

<body>
    <div>打开浏览器控制台查看结果</div>
    <script>
        const findLastKey = (obj, handler) =>
            Object.keys(obj)
                .reverse()
                .find(key => handler(obj[key], key, obj));
        console.log(findLastKey(
            {
                barney: { age: 36, active: true },
                fred: { age: 40, active: false },
                pebbles: { age: 1, active: true }
            },
            x => x['active']
        ));; // 'pebbles'
    </script>
</body>

</html>